import { createRouter, createWebHistory } from "vue-router";

import VideoViewer from "@/views/common/VideoViewer.vue";

const routes = [
  {
    path: "/elliptical-rotation-chart",
    name: "EllipticalRotationChart",
    component: () => import("@/components/EllipticalRotationChart.vue"),
  },
  {
    path: "/",
    component: import("@/views/test.vue"),
    children: [
      {
        path: "community",
        name: "CommunityHome",
        component: import("@/views/common/Community.vue"),
      },
      {
        path: "my-posts", // 我的发帖页面
        name: "MyPosts",
        component: import("@/components/community/MyPosts.vue"),
      },
      {
        path: "message-centerPlus",
        name: "MessageCenterPlus",
        component: import("@/components/common/message_center.vue"),
      },
      {
        path: "message-center",
        name: "MessageCenter",
        component: import("@/components/community/MessageCenter.vue"),
      },
      {
        path: "profile", // 定义页面的访问路径
        name: "UserProfile",
        // 假设您将 UserProfile.vue 文件放在了 @/views/common/ 目录下
        component: () => import("@/components/common/UserProfile.vue"),
      },
    ],
  },
  {
    path: "/student",
    name: "Student",
    component: import("@/views/student/test1.vue"),
    children: [
      {
        path: "student-dashboard",
        name: "StudentDashboard",
        component: import("@/components/student/student-dashboard.vue"),
      },
      {
        path: "course-detail/:id",
        name: "StudentCourseDetail",
        component: () => import("@/components/student/course-detail.vue"),
      },
      {
        path: "course-list",
        name: "CourseList",
        component: import("@/components/student/course-list.vue"),
      },
      {
        path: "learning-center",
        name: "LearningCenter",
        component: import("@/components/student/learning-center.vue"),
      },
      {
        path: "take-exam/:examId", // 使用 :examId 作为路径参数
        name: "StudentTakeExam",
        component: () => import("@/components/student/StudentTakeExam.vue"),
        // meta: { requiresAuth: true, role: 'student' } // 可以在这里添加路由元信息用于权限控制
      },
      {
        path: "student-assessment",
        name: "StudentAssessment",
        component: import("@/components/student/student-assessment.vue"),
      },
      {
        path: "student-assessment-plus",
        name: "StudentAssessmentPlus",
        component: import("@/components/student/student-assessment-plus.vue"),
      },
      {
        path: "student-training-plan",
        name: "StudentTrainingPlan",
        component: import("@/components/student/training-plan.vue"),
      },
      {
        path: "class/:id",
        name: "Class",
        component: import("@/components/student/course-detail.vue"),
      },
    ],
  },
  {
    path: "/admin",
    name: "Admin",
    component: import("@/views/admin/test2.vue"),
    children: [
      {
        path: "course-detail/:id",
        name: "CourseDetail",
        component: import("@/components/teacher/TeacherCourseDetail.vue"),
      },
      {
        path: "admin-assessment-plus",
        name: "AdminAssessmentPlus",
        component: import("@/components/admin/AdminAssessment.vue"),
      },
      {
        path: "admin-assessment",
        name: "AdminAssessment",
        component: import("@/components/admin/adminAssessmentPlus.vue"),
      },
      {
        path: "admin-course",
        name: "AdminCourse",
        component: import("@/components/admin/AdminCourse.vue"),
      },
      {
        path: "log",
        name: "Log",
        component: import("@/components/admin/AdminLog.vue"),
      },
      {
        path: "admin-training-plan",
        name: "AdminTrainingPlan",
        component: import("@/components/admin/AdminPlanning.vue"),
      },
      {
        path: "user",
        name: "User",
        component: import("@/components/admin/AdminUser.vue"),
      },
      {
        path: "admin-dashboard",
        name: "AdminDashboard",
        component: import("@/components/admin/AdminDashboard.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: import("@/components/common/login.vue"),
  },
  {
    path: "/register",
    name: "Register",
    component: import("@/components/common/register.vue"),
  },
  // {
  //   path: "/modal",
  //   name: "Modal",
  //   component: import("@/components/ModalViewer.vue"),
  // },
  {
    path: "/learning",
    name: "Learning",
    component: VideoViewer,
  },
  /*
   *这里gitee上没有这个文件，先注释掉
   */
  {
    path: "/learning/document",
    name: "LearningDocument",
    component: import("@/views/common/DocumentViewer.vue"),
  },
  {
    path: "/home",
    name: "HomeHome",
    component: import("@/views/common/Home.vue"),
  },
  {
    path: "/course",
    name: "Course",
    component: import("@/views/teacher/test3.vue"),
    children: [
      {
        path: ":id",
        name: "CourseDetail",
        component: import("@/components/teacher/TeacherCourseDetail.vue"),
      },
    ],
  },
  {
    path: "/teacher",
    name: "Teacher",
    component: import("@/views/teacher/test3.vue"),
    children: [
      {
        path: "teacher-planning",
        name: "TeacherPlanning",
        component: import("@/components/teacher/TeacherTrainingPlan.vue"),
      },
      {
        path: "teacher-dashboard",
        name: "TeacherDashboard",
        component: import("@/components/teacher/teacher-dashboard.vue"),
      },
      {
        path: "teacher-assessment",
        name: "TeacherAssessment",
        component: import("@/components/teacher/TeacherAssessment.vue"),
      },
      {
        path: "training-plan",
        name: "TeacherTrainingPlan",
        component: import("@/components/teacher/TeacherTrainingPlan.vue"),
      },
      {
        path: "/teacher/exam-questions/:examId", // 使用 :examId 占位符
        name: "ExamQuestions",
        component: () => import("@/components/teacher/ExamQuestions.vue"), // 假设新页面放在这个路径
      },
      {
        path: "training-plan/:id",
        name: "TeacherTrainingPlanDetail",
        component: import("@/components/teacher/TeacherTrainingPlanDetail.vue"),
      },
      {
        path: "teacher-course",
        name: "TeacherCourse",
        component: () => import("@/components/teacher/TeacherCourse.vue"),
      },
      {
        path: "teacher-user",
        name: "TeacherUser",
        component: import("@/components/teacher/TeacherUser.vue"),
      },
      {
        path: "/grade-submission/:submissionId",
        name: "GradeSubmission",
        component: () => import("@/components/teacher/GradeSubmission.vue"), // 确保路径正确
        meta: {
          title: "批改答卷",
          requiresAuth: true, // 假设需要登录才能访问
          roles: ["INSTRUCTOR"], // 假设只有教师角色可以访问
        },
      },
      {
        path: "/exam/:examId/submissions",
        name: "SubmissionList",
        component: () => import("@/components/teacher/SubmissionList.vue"), // 确保路径正确
        meta: {
          title: "答卷列表",
          requiresAuth: true,
          roles: ["INSTRUCTOR"],
        },
      },
    ],
  },
  {
    path: "/exam",
    name: "Exam",
    component: import("@/views/student/Exam.vue"),
    children: [
      {
        path: "before",
        name: "Before",
        component: import("@/components/student/exam-before.vue"),
      },
      {
        path: "during",
        name: "During",
        component: import("@/components/student/exam-during.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// // 全局前置守卫
// router.beforeEach((to, from, next) => {
//   // 需要登录的页面路径
//   const authPages = [
//     "/landlord/orders",
//     "/landlord/houses",
//     "/landlord/applications",
//   ];
//   const isAuthPage = authPages.includes(to.path);
//   const isLoggedIn = !!sessionStorage.getItem("Authorization");
//   if (isAuthPage && !isLoggedIn) {
//     next("/welcome/login");
//   } else {
//     next();
//   }
// });

export default router;
